home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 90 / CD Actual 90.iso / Software3D / K-3D / k3d-0.4.2.1 / shaders / k3d_venus2.sl < prev    next >
Encoding:
Text File  |  2004-07-23  |  3.2 KB  |  98 lines

  1. /* I renamed the shader to MBVenus.sl -- tal@SpamSucks_cs.caltech.edu */
  2.  
  3. /*
  4.  * venus.sl - surface for a very cloudy planet like Venus.
  5.  *
  6.  *
  7.  * DESCRIPTION:
  8.  *      When put on a sphere, sets the color to look like a densely
  9.  *   clouded planet, very much like the real Venus appears in UV.
  10.  *      The shader works by creating a fractal turbulence function over
  11.  *   the surface to simulate the clouds.  Strong Coriolis forces are
  12.  *   simulated to give the twisting of clouds that is typically seen
  13.  *   on Venus.
  14.  *
  15.  *
  16.  * PARAMETERS:
  17.  *    Ka, Kd - the usual meaning
  18.  *    offset, scale - control the linear scaling of the cloud value.
  19.  *    twist - controls the twisting of the clouds due to Coriolis forces.
  20.  *    omega - controls the fractal characteristics of the clouds
  21.  *    octaves - the number of octaves of noise to sum for the clouds.
  22.  *    radius - radius of planet
  23.  *
  24.  *
  25.  * AUTHOR: Ken Musgrave.
  26.  *    Conversion to Shading Language and minor modifications by Larry Gritz.
  27.  *    Planet radius param added by Mark Beckwith.
  28.  *
  29.  * REFERENCES:
  30.  *    _Texturing and Modeling: A Procedural Approach_, by David S. Ebert, ed.,
  31.  *    F. Kenton Musgrave, Darwyn Peachey, Ken Perlin, and Steven Worley.
  32.  *    Academic Press, 1994.  ISBN 0-12-228760-6.
  33.  *
  34.  *
  35.  * HISTORY:
  36.  *    ???? - Venus texture developed by F. Ken Musgrave.
  37.  *    Feb 1994 - Conversion to Shading Language by L. Gritz
  38.  *    Dec 1996 - Added radius of planet as a parameter by Mark Beckwith
  39.  *        (mark@SpamSucks_intrig.com)
  40.  */
  41.  
  42.  
  43.  
  44. #define TWOPI (2*PI)
  45.  
  46.  
  47. /* Use signed noise on [-1,1] */
  48. #define snoise(x) ((2*noise(x))-1)
  49.  
  50.  
  51.  
  52. surface
  53. k3d_venus2 (float Ka = 1, Kd = 1;
  54.        float offset = 1;
  55.        float scale = 0.6;
  56.        float twist = 0.22;
  57.        float omega = 0.65;
  58.        float octaves = 8;
  59.        float radius = 1)
  60. {
  61.   point Ptexture;           /* the shade point in texture space */
  62.   point PtN;                /* normalized version of Ptexture */
  63.   point PP;                 /* Point after rotation by coriolis twist */
  64.   float rsq;                /* Used in calculation of twist */
  65.   float angle;              /* Twist angle */
  66.   float sine, cosine;       /* sin and cos of angle */
  67.   float l, o, a, i;         /* Loop control for fractal sum */
  68.   float value;              /* Fractal sum is stored here */
  69.  
  70.   /* Transform to texture coordinates and map to nit sphere */
  71.   Ptexture = transform ("shader", P) / radius;
  72.  
  73.   /* Calculate Coriolis twist, yielding point PP */
  74.   PtN = normalize (Ptexture);
  75.   rsq = xcomp(PtN)*xcomp(PtN) + ycomp(PtN)*ycomp(PtN);
  76.   angle = twist * TWOPI * rsq;
  77.   sine = sin (angle);
  78.   cosine = cos (angle);
  79.   PP = point (xcomp(Ptexture)*cosine - ycomp(Ptexture)*sine,
  80.           xcomp(Ptexture)*sine + ycomp(Ptexture)*cosine,
  81.           zcomp(Ptexture));
  82.  
  83.   /* Compute VLfBm */
  84.   l = 1;  o = 1;  a = 0;
  85.   for (i = 0;  i < octaves;  i += 1) {
  86.       a += o * snoise (PP * l);
  87.       l *= 2;
  88.       o *= omega;
  89.     }
  90.  
  91.   value = abs (offset + scale * a);
  92.  
  93.   /* Shade like matte, but with color scaled by cloud color */
  94.   Oi = 1;
  95.   Ci = Os * (value * Cs) * (Ka * ambient() +
  96.                 Kd * diffuse(faceforward(normalize(N),I)));
  97. }
  98.